home *** CD-ROM | disk | FTP | other *** search
/ Network Support Library / RoseWare - Network Support Library.iso / apidev / sc3x04.exe / CUSEFILE.C < prev    next >
Text File  |  1993-04-23  |  6KB  |  160 lines

  1. //   ╔════════════════════════════════════════════════════════════════════╗
  2. //   ║                                                                    ║
  3. //   ║ module:      3xsc.c                                                ║
  4. //   ║ abstract:    This module shows how to make 3.x system calls using  ║
  5. //   ║              the F2 Shell Interface.  Obviously, it requires the   ║
  6. //   ║              NetWare Shell.                                        ║
  7. //   ║                                                                    ║
  8. //   ║ environment: NetWare 3.x v3.11                                     ║
  9. //   ║              Borland C 3.0                                         ║
  10. //   ║                                                                    ║
  11. //   ║  This software is provided as is and carries no warranty           ║
  12. //   ║  whatsoever.  Novell disclaims and excludes any and all implied    ║
  13. //   ║  warranties of merchantability, title and fitness for a particular ║
  14. //   ║  purpose.  Novell does not warrant that the software will satisfy  ║
  15. //   ║  your requirements or that the software is without defect or error ║
  16. //   ║  or that operation of the software will be uninterrupted.  You are ║
  17. //   ║  using the software at your risk.  The software is not a product   ║
  18. //   ║  of Novell, Inc. or any of subsidiaries.                           ║
  19. //   ║                                                                    ║
  20. //   ║      ****    NOTICE    ****    NOTICE   ****   NOTICE   ****       ║
  21. //   ║                                                                    ║
  22. //   ║  This example code has not been extensively tested and therefore   ║
  23. //   ║  should be run on a test server before used in a production en-    ║
  24. //   ║  vironment.  Also, a backup is recommended before the installation ║
  25. //   ║  of any untested component.                                        ║
  26. //   ╟────────────────────────────────────────────────────────────────────╢
  27. //   ║ maintenance history:                                               ║
  28. //   ║ level    date      pi   description                                ║
  29. //   ╟────────────────────────────────────────────────────────────────────╢
  30. //   ║  001   10/01/92    cm   Intial release.                            ║
  31. //   ║  002   04/23/93    mp   Added missing prototypes, fixed sopen call ║
  32. //   ╚════════════════════════════════════════════════════════════════════╝
  33.  
  34. #include <conio.h>
  35. #include <io.h>
  36. #include <stdio.h>
  37. #include <string.h>
  38. #include <stdlib.h>
  39. #include <dos.h>
  40. #include "nwsys.h"
  41. #include <share.h>
  42. #include <fcntl.h>
  43. #include <sys/stat.h>
  44.  
  45. //
  46. //  First of all, we define the request and reply structures which are
  47. //  needed for the ScanConnectionsUsingFile API call.  These structures are
  48. //  layed out according to the System Call documentation.
  49. //
  50.  
  51. struct  {
  52.      WORD    sflen;          // length of the structure
  53.      BYTE    sfcode;         // the subfunction code
  54.      BYTE    forkType;       // type of file
  55.      BYTE    volumeNumber;   // volume number
  56.      LONG    sequenceNumber; // dirEntry sequence number
  57.      WORD    lastRecordSeen; // last record
  58. } Request;
  59.  
  60. typedef struct {
  61.     WORD    connectionNumber;  // connection number holding file open
  62.     WORD    taskNumber;        // task holding file open
  63.     BYTE    lockType;          // lock type
  64.     BYTE    accessFlag;        // access
  65.     BYTE    lockFlag;          // lock flag
  66. } CONN_INFO;
  67.  
  68. struct {
  69.     WORD     nextRequest;       // next record
  70.     WORD  useCount;          // use count
  71.     WORD  openCount;         // total times file is open
  72.     WORD    openForReadCount;  // total open for read
  73.     WORD    openForWriteCount; // total open for write
  74.     WORD  denyReadCount;     // deny read flag/total
  75.     WORD  denyWriteCount;    // deny write flag/total
  76.     BYTE    locked;            // lock status
  77.     BYTE     fork;              // file type
  78.     WORD    connCount;         // number of connection entries
  79.     CONN_INFO
  80.             connInfo[70];      // individual connection info
  81. } Reply;
  82.  
  83. //
  84. //  This is the main program.  The purpose is to make the ScanConnections
  85. //  UsingFiles API call to illustrate making system calls using the F2
  86. //  interface.
  87. //
  88.  
  89. int ConvertPathToDirEntry(char *path, BYTE *volume, LONG *dirEntry);
  90.  
  91. int main(int argc, char *argv[])
  92. {
  93.     int   cc;
  94.     char    dirPath[255];
  95.     BYTE    volumeNumber;
  96.     LONG    sequenceNumber;
  97.     int    fileHandle;
  98.  
  99.     if(argc!=2) {
  100.         printf("usage: cusefile FullPath\n");
  101.         exit(1);
  102.     }
  103.     strcpy(dirPath,argv[1]);
  104.     fileHandle=sopen(dirPath, O_TEXT, SH_DENYNO);
  105.     if(fileHandle == -1) {
  106.         printf("\nUnable to open %s.",dirPath);
  107.         exit(1);
  108.     }
  109.     //
  110.     //  Build the request buffer
  111.     //
  112.     cc=ConvertPathToDirEntry(dirPath, &volumeNumber, &sequenceNumber);
  113.     if( cc ) {
  114.         printf("%s not Found.",dirPath);
  115.         exit(1);
  116.     }
  117.     Request.sflen = (sizeof Request) ;
  118.     Request.sfcode = 236;                       // subfunction code
  119.     Request.forkType = 0;
  120.     Request.volumeNumber = volumeNumber;
  121.     Request.sequenceNumber = sequenceNumber;
  122.     Request.lastRecordSeen = 0;
  123.     cc = NWSystemCall(23,&Request,sizeof Request,&Reply,sizeof Reply);
  124.     printf("Function returned:    %03d--%#02x\n",cc,cc);
  125.     printf("\nPress any key to close file!");
  126.     getch();
  127.     close(fileHandle);
  128.     return 0;
  129. }
  130.  
  131. int ConvertPathToDirEntry(char *path, BYTE *volume, LONG *dirEntry)
  132. {
  133.     static struct {
  134.         WORD  sflen;             // length of the structure
  135.         BYTE  sfcode;            // the subfunction code
  136.         BYTE  dirHandle;         // type of file
  137.         BYTE  pathStringLength;  // length of path
  138.         BYTE  pathString[255];   // path
  139.     } dirEntryRequest;
  140.  
  141.    static struct {
  142.         BYTE    volumeNumber;   // volume number
  143.         LONG    dirEntry;       // directory entry sequence
  144.     } dirEntryReply;
  145.     int    cc;
  146.  
  147.     dirEntryRequest.sflen=sizeof(dirEntryRequest);
  148.     dirEntryRequest.sfcode=0xF4;
  149.     dirEntryRequest.dirHandle=0x00;
  150.     dirEntryRequest.pathStringLength=strlen(path);
  151.     memcpy(&dirEntryRequest.pathString,path,strlen(path));
  152.     cc = NWSystemCall(23,&dirEntryRequest,sizeof dirEntryRequest,&dirEntryReply,sizeof dirEntryReply);
  153.     if( !cc) {
  154.         *volume=dirEntryReply.volumeNumber;
  155.         *dirEntry=dirEntryReply.dirEntry;
  156.     }
  157.     return( cc );
  158. }
  159. 
  160.